Add YYYYMMDD_TIME GEOCACHE_LAST_FOUND GEOCACHE_HINT GEOCACHE_PLACER to
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Thu, 5 May 2005 16:32:55 +0000 (16:32 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Thu, 5 May 2005 16:32:55 +0000 (16:32 +0000)
the CSV handlers.

gpsbabel/csv_util.c
gpsbabel/internal_styles.c
gpsbabel/style/README.style
gpsbabel/style/tabsep.style

index 02cb3ebf8b2db9546d16e333db549faec065fab4..e2423a5b1f3b6dd34b322feb03c60eea50624986 100644 (file)
@@ -2,6 +2,7 @@
     Utilities for parsing Character Separated Value files (CSV)
 
     Copyright (C) 2002 Alex Mottram (geo_alexm at cox-internet.com)
+    Copyright (C) 2002-2005 Robert Lipe
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -603,6 +604,37 @@ xcsv_epilogue_add(char *epilogue)
     xcsv_file.epilogue_lines++;
 }
 
+static
+time_t
+yyyymmdd_to_time(const char *s)
+{
+       int t = atol(s);
+       struct tm tm;
+
+       memset(&tm, 0, sizeof(tm));
+
+       tm.tm_mday = t % 100;
+       t = t / 100;
+       tm.tm_mon = t % 100 - 1;
+       t = t / 100;
+       tm.tm_year = t - 1900;
+       return mktime(&tm);
+}
+
+static 
+long 
+time_to_yyyymmdd(time_t t)
+{
+       long b;
+       struct tm *tm = gmtime(&t);
+
+       b = (1900 + tm->tm_year) * 10000 + 
+               (1 + tm->tm_mon) * 100 + 
+               tm->tm_mday;
+
+       return b;
+}
+
 /*****************************************************************************/
 /* xcsv_parse_val() - parse incoming data into the waypt structure.          */
 /* usage: xcsv_parse_val("-123.34", *waypt, *field_map)                      */
@@ -713,6 +745,12 @@ xcsv_parse_val(const char *s, waypoint *wpt, const field_map_t *fmp)
        /* Time as time_t */
        wpt->creation_time = atol(s);
      } else
+    if (strcmp(fmp->key, "YYYYMMDD_TIME") == 0) {
+       wpt->creation_time = yyyymmdd_to_time(s);
+    } else
+    if (strcmp(fmp->key, "GEOCACHE_LAST_FOUND") == 0) {
+       wpt->gc_data.last_found = yyyymmdd_to_time(s);
+    } else
 
     /* GEOCACHING STUFF ***************************************************/
     if (strcmp(fmp->key, "GEOCACHE_DIFF") == 0) {
@@ -730,6 +768,14 @@ xcsv_parse_val(const char *s, waypoint *wpt, const field_map_t *fmp)
     if (strcmp(fmp->key, "GEOCACHE_CONTAINER") == 0) {
        wpt->gc_data.container = gs_mkcont(s);
     } else
+    if (strcmp(fmp->key, "GEOCACHE_HINT") == 0) {
+       wpt->gc_data.hint = csv_stringtrim(s, "", 0);
+    } else
+    if (strcmp(fmp->key, "GEOCACHE_PLACER") == 0) {
+       wpt->gc_data.placer = csv_stringtrim(s, "", 0);
+    } else
+       
+    /* OTHER STUFF ***************************************************/
     if ( strcmp( fmp->key, "PATH_DISTANCE_MILES") == 0) {
        /* Ignored on input */
     } else
@@ -1069,6 +1115,12 @@ xcsv_waypt_pr(const waypoint *wpt)
             /* time as a time_t variable */
             sprintf(buff, fmp->printfc, wpt->creation_time);
         } else
+        if (strcmp(fmp->key, "YYYYMMDD_TIME") == 0) {
+           sprintf(buff, fmp->printfc, time_to_yyyymmdd(wpt->creation_time));
+       } else
+        if (strcmp(fmp->key, "GEOCACHE_LAST_FOUND") == 0) {
+           sprintf(buff, fmp->printfc, time_to_yyyymmdd(wpt->gc_data.last_found));
+       } else
 
         /* GEOCACHE STUFF **************************************************/
         if (strcmp(fmp->key, "GEOCACHE_DIFF") == 0) {
@@ -1086,6 +1138,12 @@ xcsv_waypt_pr(const waypoint *wpt)
        if (strcmp(fmp->key, "GEOCACHE_TYPE") == 0) {
             /* Geocache Type */
             sprintf(buff, fmp->printfc, gs_get_cachetype(wpt->gc_data.type));
+        } else 
+       if (strcmp(fmp->key, "GEOCACHE_HINT") == 0) {
+           sprintf(buff, fmp->printfc, NONULL(wpt->gc_data.hint));
+        } else 
+       if (strcmp(fmp->key, "GEOCACHE_PLACER") == 0) {
+           sprintf(buff, fmp->printfc, NONULL(wpt->gc_data.placer));
         } else {
            /* this should probably never happen */
         }
index aec526d801643349b0630b119bf4612a02a29460..49efddea315c37b08e97a7b10e9645c0828a3741 100644 (file)
@@ -498,6 +498,8 @@ static char tabsep[] =
 "IFIELD  GEOCACHE_TYPE,\"\",\"%s\"\n"
 "IFIELD  PATH_DISTANCE_MILES,\"\",\"%f\"\n"
 "IFIELD  PATH_DISTANCE_KM, \"\", \"%f\"\n"
+"IFIELD  GEOCACHE_PLACER,\"\",\"%s\"\n"
+"IFIELD  YYYYMMDD_TIME,\"\",\"%ld\"\n"
 ;
 static char xmap[] = 
 "# gpsbabel XCSV style file\n"
index 9a05d4b623e1d55ebf10ef894dc5c48519800ff0..bbd30e6374202d95a716318051dae886150b788e 100644 (file)
@@ -342,6 +342,14 @@ The fields used by the XCSV parser are as follows:
    
    example: IFIELD TIMET_TIME,"","%ld"
 
+ o YYYYMMDD_TIME
+   TIMET_TIME is the waypoint's creation time, if any.  It's a single
+   decimal field containing four digits of year, two digits of month, 
+   and two digits of date.   Internally it is a LONG INTEGER and thus
+   requires a LONG INTEGER printf conversion.
+
+   example: IFIELD YYYYMMDD_TIME,"","%ld"
+
  o GEOCACHE_DIFF
    GEOCACHE_DIFF is valid only for geocaches and represents a DOUBLE 
    PRECISION FLOAT.  A "three and a half star" cache would therefore be "3.5"
@@ -368,6 +376,24 @@ The fields used by the XCSV parser are as follows:
 
    example: GEOCACHE_TYPE,"","%s"
 
+ o GEOCACHE_PLACER
+   GEOCACHE_PLACER is a string containing the name of the placer of a 
+   geocache.   
+
+   example: GEOCACHE_PLACER,"","%s"
+
+ o GEOCACHE_LAST_FOUND
+   A long integer in format YYYYMMDD containing the last time this geocache
+   was found.
+
+   example: GEOCACHE_LAST_FOUND,"","%ld"
+
+ o GEOCACHE_HINT
+   The hint for this geocache.   No additional transformation (such as rot13)
+   will be performed on this string.
+
+   example: GEOCACHE_HINT,"","%s"
+
  o PATH_DISTANCE_MILES
    PATH_DISTANCE_MILES outputs the total length of the route or track from
    the start point to the current point, in miles.  This and the altitude
index 7176e813e2a343be25d39c18a5b89e7426ec74ac..b65b776861baa15f64710ed49c391cedf7bc04b5 100644 (file)
@@ -51,3 +51,5 @@ IFIELD  GEOCACHE_CONTAINER,"","%s"
 IFIELD  GEOCACHE_TYPE,"","%s"
 IFIELD  PATH_DISTANCE_MILES,"","%f"
 IFIELD  PATH_DISTANCE_KM, "", "%f"
+IFIELD  GEOCACHE_PLACER,"","%s"
+IFIELD  YYYYMMDD_TIME,"","%ld"